package com.example.shop;

import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class InfActivity extends AppCompatActivity {

    ImageView ima;
    String name = "";
    String price = "";
    String profile = "";
    String img = "";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);//隐藏标题栏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//隐藏状态栏
        setContentView(R.layout.activity_inf);
        TextView tv_main_title =findViewById(R.id.tv_main_title);

        tv_main_title.setText("商品详情");
        RelativeLayout rl_title_bar = findViewById(R.id.title_bar);
        rl_title_bar.setBackgroundColor(Color.rgb(255, 165, 0));
        TextView titleTv = findViewById(R.id.title_tv);
        TextView pubtimeTv = findViewById(R.id.price_tv);
        TextView contentTv = findViewById(R.id.content_tv);
        ima = findViewById(R.id.imv);
        TextView add_to_cart = findViewById(R.id.add_to_cart);
        //返回键
        ImageView iv_back = findViewById(R.id.iv_back);

        iv_back.setOnClickListener(v -> {
            //返回键
            InfActivity.this.finish();
        });

        contentTv.setMovementMethod(new ScrollingMovementMethod());

        Intent intent = getIntent();
        name = intent.getStringExtra("name");
        price = intent.getStringExtra("price");
        profile = intent.getStringExtra("profile");
        img = intent.getStringExtra("image");
        titleTv.setText(name);
        pubtimeTv.setText(String.format("¥%s", price));
        contentTv.setText(profile);
        ima.setImageURI(Uri.parse(img));
        add_to_cart.setOnClickListener(v -> {
            Intent intent1 = new Intent();
            intent1.putExtra("name", name);
            intent1.putExtra("profile", profile);
            intent1.putExtra("price", price);
            intent1.setClass(InfActivity.this, BuyActivity.class);
            startActivity(intent1);
            //InfActivity.this.finish();
        });
    }
}
